package com.situ.service.impl;

import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;
import com.situ.dao.SalChanceDao;
import com.situ.entity.SalChance;
import com.situ.service.SalChanceService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * SalChance的服务接口的实现类
 * 
 * @author 胡文 qq:986776
 *
 */
@Service
public class SalChanceServiceImpl implements SalChanceService {
	private final Logger LOG = LogManager.getLogger(this.getClass());

	@Autowired
	private SalChanceDao salChanceDao;

/**
* 查询....
*/
	@Override
	public List<SalChance> find(SalChance value) {

		List<SalChance> result = salChanceDao.selectSalChanceByObj(value);

		return result;
	}
@Override
	public PageInfo<SalChance> find2(String chc_cust_name,String chc_title,String chc_linkman,int pageNum,int pageSize) {
		PageMethod.startPage(pageNum,pageSize);
		List<SalChance> result = salChanceDao.selectSalChanceByObj2(chc_cust_name,chc_title,chc_linkman);
	PageInfo<SalChance> pages = new  PageInfo<>(result,7);
		return pages;
	}
    /**
* 根据id查询
*/
	@Override
	public SalChance findOne(Long id) {

		SalChance result = salChanceDao.selectSalChanceById(id);

		return result;
	}

/**
* 添加不为空
*/
	@Override
	public SalChance saveNotNull(SalChance sales) {
		if (sales == null) {
			if (LOG.isDebugEnabled()) {
				LOG.debug("执行将SalChance中属性值不为null的数据保存到数据库-->失败:对象不能为空");
			}
			return sales;
		}
		if(sales.getChc_cust_name() == null || sales.getChc_title() == null || sales.getChc_desc() == null || sales.getChc_create_id() == null || sales.getChc_create_by() == null || sales.getChc_create_date() == null || sales.getChc_status() == null  ){
			if (LOG.isDebugEnabled()) {
				LOG.debug("执行将SalChance中属性值不为null的数据保存到数据库-->失败:存在不能为空的空值");
			}
			return sales;
		}
		int result = salChanceDao.insertNotNullSalChance(sales);
		if (LOG.isDebugEnabled()) {
			LOG.debug("执行将SalChance中属性值不为null的数据保存到数据库-->结果:", result);
		}
		return sales;
	}
	@Override
    /**
* 修改不为空
*/
	public int updateNotNullById(SalChance sales) {
		if (sales == null) {
			if (LOG.isDebugEnabled()) {
				LOG.debug("执行通过SalChance的id更新SalChance中属性不为null的数据-->失败:对象为null");
			}
			return 0;
		}
		int result = salChanceDao.updateNotNullSalChanceById(sales);
		if (LOG.isDebugEnabled()) {
			LOG.debug("执行通过SalChance的id更新SalChance中属性不为null的数据-->结果:", result);
		}
		return result;
	}

	@Override
	public int updateSalChance(SalChance sales) {
		int rows = salChanceDao.updateSalChance(sales);
		return rows;
	}

	/**
* 删除
*/
	@Override
	public int deleteById(Long id) {
		if (id == null) {
			if (LOG.isDebugEnabled()) {
				LOG.debug("执行通过SalChance的id删除SalChance-->失败:id不能为空");
			}
			return 0;
		}
		int result = salChanceDao.deleteSalChanceById(id);
		if (LOG.isDebugEnabled()) {
			LOG.debug("执行通过SalChance的id删除SalChance-->结果:", result);
		}
		return result;
	}


}